The DATASTORE device, is used to manage the reads and writesof the removable memory MMC (Multi Media Card) and in the non-removable memory (NAND) of the Qmove family instruments.
In the configuration unit, the BUS section must be declared so that you have the hardware resources required for the implementation of the DATASTORE device.
;--------------------------------- ; Internal device declaration ;--------------------------------- INTDEVICE <device name> DATASTORE TCamp <port_type>
where:
| <device name> | The name given to the device. |
| DATASTORE | Keyword that identifies the device. |
| Tcamp | Time sampling device (1÷10 ms). |
| <port type> | Connected port type (MMC on port 0) |
;-------------------------------- ; Internal device declaration ;-------------------------------- INTDEVICE DEV DATASTORE 0001 0
The access to MMC storage device, it is implemented through a “file_system” and not with direct access. In this way the saved data can be shared with any PC and the device is seen by it as a simple floppy disk.
File system features
The file system supports the following types of FAT:
FAT12 Used on floppy disks or storage devices with limited capacity.
FAT16 Used in most storage devices. It can get to store 2 GB of data.
FAT32 Used in high-capacity storage devices, over 2 GB.
The file-system implemented, allows access to the file for reading and writing. Does not allow you to create directories, and then those files must be present in the single “root directory” . The device is also able to open/create files whose names or ASCII conversion of a number and the extension is fixed.
Supports two types of files:
Supported file formats are the BINART and the CSV. In our implementation are available the reading and appending functions (writing to END file), but not overwrite function on all types of files.
BINARY format The binary files have “hex” extension. In our implementation you can write and read a binary file where data values are stored in long (32bits) in hexadecimal base (HEX). To write or read such a file you must set the parameter filetype = 0.
If in the olongXX variables we have the following values:
olong01 = 0 => H'00000000 olong02 = -1 => H'FFFFFFFF olong03 = 10000 => H'00002710 olong04 = -10000 => H'FFFFD8F0
We run the WRITE command by setting the parameter “field = 4”, we get to the end of the file:
00000000FFFFFFFF00002710FFFFD8F0''
CSV format The csv file will have “csv” extension. Data written in these files are organized in a table formed from a settable number of columns, each column is called a “field”. The rows of the table are called “record”. The DATASTORE device does not consider the presence of the record header. The maximum number of field is set to 32 (ilong / olong).
To write some long data type, “10000”, “-1”, “2147483647” and “-2147483648”, by setting the “filetype = 1” parameter, we will have:
The file system supports the following types of FAT:
Field1------------ +Field2--------- +Field3-------- +Field4-----+ 10000 -1 2147483647 '2000000000
In this way the occupation of space in each record is fixed. If we set instead “filetype = 3”, we will have:
10000;-1;2147483647;'2000000000
The major evaluation software including Microsoft Excel, OpenOffice, Lotus 123, successfully read the fixed width file (filetype = 1) but when you save it into file with the field delimiters (filetype = 3).
The main difference between a format and the other is in the search of records.
Read a particular record using the format 1, It is not difficult as the start position within the file can be calculated easily given the record length is fixed.
Read instead a record with the format 2, implies a search within the file record start position. This operation may be long.
To use the (MMC) storage device You must use the device command that allows to recognize it and activate it. The MOUNT command allow to execute this operationn. The device will be activated when the state st_mount take the value 1.
Please note that after each command, the device marks is handling that command with the st_busy state. When the st_busy state is to 1 the device cannot access other commands.
To open an existing file or open a new file, set the filetype parameter. It allows you to specify the format of the file you intend to treat.
Below we will divide the discussion on whether the filetype parameter takes the following values:
a) 0: binary files;
b) 1-2: CSV file with fixed space for data;
c) 3-4: CSV file with data separated by “;”.
Before sending the command of opening the file you have to specify which file is open with the filenuum parameter.
If the file is present in the storage device it is open otherwise it creates a new file with the name specified in filenum file.
When the st_openfile state is to 1 the file is opened.
a) In the binary files data is present one after the other. It's possible:
To read one or more data to a binary file, you must set the record parameter what data you begin reading and in the filed parameter how much data to read up to 32 data with one reading. At this point you have to use the READ command.
Data read are shown in the ilong01÷ ilong32 parameters.
Reading of 3 data in the position 11, 12, 13 in the binary file.
DEV:record=11 DEV:field=3 READ DEV WAIT NOT DEV: st_busy glVar1=DEV: ilong01 glVar2=DEV: ilong02 glVar3=DEV: ilong03
To write one or more data to a binary file you must set therecord parameter what data start overwrite and in the field parameter how much data will overwrite.
Data values by overwriting the data in the file should be inserted into olong01÷ olong32 parameters.
Writing of 3 datas int the position 11, 12, 13 in the binary file.
DEV:record=11 DEV:field=3 DEV:olong01=123 ;first data DEV:olong02=456 ;second data DEV:olong03=789 ;third data WRITE DEV WAIT NOT DEV: st_busy
To append new data to a binary file, you must use the method described above remembering to set the record parameter to -1.
B) In the CSV files with fixed datas space, is creates a table with columns, called field, and rows, called record. The field numbers with which to create the table you must specify before you open the new file in the field parameter.
For each entry in this table is reserved a fixed space. In this way each record, composed of a number field of data, fixed space in file.
To read a record of such a file, you must set in the record parameter, the number of records to read and send the READ command. In the ilong01-ilong32 parameters, are shows the read values from the record.
To overwrite a record of such a file, set the parameter records the number of records to write, set in the olong01-olong32 paramenters a number of values equal to the number of field in the record and then send the WRITE command.
To append a new record to the file you must set the value -1 in record.
Read of the record 3 (Composed of three field):
DEV:record = 3 READ DEV glVar1 = DEV:ilong01 glVar2 = DEV:ilong02 glVar3 = DEV:ilong03
C) As in the case B, but in this case you cannot read or overwriting a particular record. You can only read sequentially around the file and write just by adding a new record.
Summary table:
| Operations | filetype | ||
|---|---|---|---|
| 0 | 1-2 | 3-4 | |
| OPEN/CLOSE | yes | yes | yes |
| DELETE | yes | yes | yes |
| READ sequential records* | yes | yes | yes |
| READ indexed records* | yes | yes | no |
| WRITE ad a record | yes | yes | yes |
| WRITE overwrite a record | yes | yes | no |
* = READ sequential records: reading of records in file starting from the first record to the last. This kind of reading does not provide the ability to read records in random order within the file. This kind of reading are only going to read records from the first and reading always following the last read.
* * = READ indexed records: This kind of reading can read any record in the file even in random order.
The name of the parameter, state or command is shows at the left of the table.
R
Indicates if the parameter or state is retentive (upon initialization of the device maintains the previously defined state), or the state assumes upon initialization of the device.
If the device does not need to initialize the “R” field indicates the value that the parameter take to power up of the card.
R = Retentive
0 = Upon initialization of the device the value is forced to zero.
1 = Upon initialization of the device the value is forced to one.
- = Upon initialization of the device is presented significant value.
D
Indicates the paramenter size.
F = Flag
B = Byte
W = Word
L = Long
S = Single Float
Are describe all conditions that must exist is considered correct or because the command is accepted.
In some cases, limit values are specified for the acceptance of the parameter: If there are any values outside the limits set, the data is in any case accepted; ptherefore appropriate controls of the application must be provided to ensure the proper functioning.
To run a command, all the conditions must be met; otherwise the command is not sent.
A
Indicates the access mode.
R = Read.
W = Write.
RW,= Read / Write.
Di seguito sono presentati i parametri, variabili, stati e comandi necessari allesecuzione del device.
| Nome | D | R | A | Condizioni | Descrizione |
|---|---|---|---|---|---|
| priority | B | 5 | R-W | - | Priority Nei prodotti della serie Qmove indica la priorità di esecuzione del device rispetto all'esecuzione dei tasks QCL e del display (Range 0÷10). Nei prodotti della serie Qmove+ indica il media a cui il device fa riferimento (0 = SD/MMC, 1=NAND interna, 2= USB). |
| filetype | B | 0 | R-W | - | File Format Definisce le caratteristiche del file (Range 0÷4): Tipo 0 type = BINARY record non separati field non separati da“,” non sono usati gli apici intestazione non presente Tipo 1 type = CSV record separati da = carrige return and line feed (Windows) field separati da spazi non sono usati gli apici intestazione non presente Tipo 2 type = CSV record separati da = line feed (Unix) field separati da spazi non sono usati gli apici intestazione non presente Tipo 3 type = CSV record separati da = carrige return and line feed (Windows) field separati da = ; (hex 3b) non sono usati gli apici intestazione non presente Tipo 4 type = CSV record separati da = line feed (Unix) field separati da = ; (hex 3b) non sono usati gli apici intestazione non presente |
| field | W | 0 | R-W | filetype=0÷4 | Field Nel caso in cui filetype=0, indica il numero di record da sovrascrivere a partire dal record indicato dal parametro record. Nel caso in cui filetype=1÷4 indica il numero di campi che saranno scritti per ogni record. Il valore è utilizzato esclusivamente con la creazione di un nuovo file. (Range 0÷32) |
| filenum | L | 0 | R-W | - | File Number Definisce il “filename” del file da aprire considerando la conversione del numero in caratteri ASCII. (Range 0÷99999999) |
| Nome | D | R | A | Condizioni | Descrizione |
|---|---|---|---|---|---|
| disksize | L | 0 | R | - | Disk Size Indica la dimensione del dispositivo di memorizzazione in bytes. Il valore è aggiornato al momento dellesecuzione del comando MOUNT. |
| diskfree | L | 0 | R | - | Disk Free Indica lo spazio libero sul dispositivo di memorizzazione in bytes. Il valore è aggiornato al momento dellesecuzione del comando MOUNT ed alla chiusura e scrittura di un file. |
| filesize | L | 0 | R | - | File Size Indica la dimensione del file in bytes. Il valore è aggiornato al momento dellapertura e ad ogni successiva operazione di scrittura. |
| numrecord | L | 0 | R | st_openfile | File Record Number Indica il numero di record presenti nel file. Il valore è aggiornato al momento dellapertura e ad ogni successiva operazione di scrittura. Se 0 significa che il file non contiene record formattati correttamente (viene settata anche la variabile error), oppure che si tratta di un nuovo file. |
| numfield | W | 0 | R | - | Field Number Indica il numero di campi presenti nel primo record letto. Il valore è aggiornato al momento della prima apertura o al momento della prima scrittura. |
| record | L | 0 | R-W | - | Record Number Indica il numero di record (row) che è processato dai comandi WRITE e READ. Se 1, con il comando WRITE sarà eseguito un accodamento. |
| ilong01÷32 | L | 0 | R | - | Input Long nr. 1 32 |
| ibyte0 | B | 0 | R | - | Input Byte 0 (LSB) ilong01 Indica il byte nr. 0 (LSB) della long ilong01 |
| ibyte1 | B | 0 | R | - | Input Byte 1 ilong01 Indica il byte nr. 1 della long ilong01 |
| ibyte2 | B | 0 | R | - | Input Byte 2 ilong01 Indica il byte nr. 2 della long ilong01 |
| ibyte3 | B | 0 | R | - | Input Byte 3 (MSB) ilong01 Indica il byte nr. 3 (MSB) della long ilong01. olong01 xxxxxxxx obyte3 xx------ (MSB) obyte2 --xx---- + obyte1 ----xx-- + obyte0 ------xx (LSB) |
| olong01-32 | L | 0 | R-W | - | Output Long nr. 1 32 |
| obyte0 | B | 0 | R-W | - | Output Byte 0 (LSB) olong01 Indica il byte nr. 0 (LSB) della long olong01 |
| obyte1 | B | 0 | R-W | - | Output Byte 1 olong01 Indica il byte nr. 1 della long olong01 |
| obyte2 | B | 0 | R-W | - | Input Byte 2 olong01 Indica il byte nr. 2 della long olong01 |
| obyte3 | B | 0 | R-W | - | Input Byte 3 (MSB) olong01 Indica il byte nr. 3 (MSB) della long olong01. ilong01 xxxxxxxx ibyte3 xx------ (MSB) ibyte2 --xx---- + ibyte1 ----xx-- + ibyte0 ------xx (LSB) |
| errcode | B | 0 | R | - | Error Code Indica lultimo errore occorso nellesecuzione dei comandi di gestione del device. 0 = no error 1 = n.d. (reserved) 2 = open file error 3 = read data error 4 = write data error 5 = file system error (reserved) 6 = file system error (reserved) 7 = file system error (reserved) 8 = file system error (reserved) 9 = file system error (reserved) 10 = record format error 11 = unknow error |
| errvalue | B | 0 | R | - | Error Value Sempre 0. |
| wrncode | B | 0 | R | - | Warning Code Indica lultimo warning occorso nellesecuzione dei comandi di gestione del device. 0 = no warning 1 = warning data 2 = warning command 3 = device not inserted |
| wrnvalue | B | 0 | R | - | Warning Value Sempre 0. |
| Nome | D | R | A | Condizioni | Descrizione |
|---|---|---|---|---|---|
| st_mount | F | 0 | R | - | Device Mount Lattivazione indica che è inserito un dispositivo di memorizzazione. Il device verifica la presenza di un nuovo dispositivo a seguito del comando MOUNT. |
| st_openfile | F | 0 | R | - | Open file Lattivazione indica che il file è stato aperto/creato correttamente. La mancata attivazione potrebbe indicare o un errore d'apertura del file: lerrore è segnalato dalla variabile error. |
| st_busy | F | 0 | R | - | Busy Lattivazione indica che il sistema è occupato in unoperazione d'accesso e che quindi non si deve togliere il supporto di memorizzazione. |
| st_error | F | 0 | R | - | Error |
| st_warning | F | 0 | R | - | Warning |
| Nome | D | R | A | Condizioni | Descrizione |
|---|---|---|---|---|---|
| MOUNT | - | - | - | st_openfile = 0 | Mount Device Verifica la presenza di un nuovo dispositivo, quindi se rilevato. Lo stato st_mount diventa 1. |
| UMOUNT | - | - | - | st_openfile = 0 | Unmount Device Questo comando serve a chiudere il dispositivo in modo che possa essere rimosso. Lo stato st_mount diventa 0. |
| OPENFILE | - | - | - | st_mount = 1 st_openfile = 0 | Open File Esegue lapertura del file filenum. Se il file non esiste, è creato. Lo stato st_openfile diventa 1. |
| CLOSEFILE | - | - | - | st_openfile = 1 | Close File Chiude il file filenum. Lo stato st_openfile diventa 0. |
| DELFILE | - | - | - | st_mount = 1 st_openfile = 0 | Delete File Elimina il file filenum. Per essere cancellato, il file deve essere chiuso. |
| READ | - | - | - | st_openfile = 1 | Read Record Esegue la lettura del record indicato dalla variabile record. Tutti i field letti sono posti nelle variabili ilongXX da ilong01. |
| WRITE | - | - | - | st_openfile = 1 | Append Record Esegue laccodamento di un nuovo record, prelevando i valori dalle variabili olongXX a partire da olong01. |
| RSERR | - | - | - | - | Clear Error Azzera la segnalazione del parametro st_error e le variabili errcode ed errvalue. |
| RSWRN | - | - | - | - | Clear Warning Azzera la segnalazione del parametro st_warning e le variabili wrncode ed wrnvalue. |
I dati tipo SINGLE non sono trattati. È necessario convertire questi dati di tipo interno prima di trasferirli nella MMC.
WAIT NOT DEV:st_busy ; necessaria perché il device alla momento del RUN
; è in uno stato di busy finchè non termina
; le operazioni di inizializzazione.
MOUNT DEV ; esegue il MOUNT del dispositivo
WAIT NOT DEV:st_busy ; attende il termine delloperazione
IF DEV:st_mount ; se il dispositivo è presente,
<operazioni> ;lo stato st_mount è 1
ENDIF
DEV:filetype = 0 ; imposta il tipo di file BINARY DEV:filenum = 123 ; imposta il nome del file come 123.hex WAIT NOT DEV:st_busy OPENFILE DEV ; esegui il comando di apertura WAIT NOT DEV:st_busy ; attende il termine delloperazione IF DEV:st_openfile ; se il file viene aperto correttamente, <operazioni> ;lo stato st_openfile è 1 ENDIF
DEV:field = 2 ; imposta il numero di campi di cui
; è composto il record
; Nota: se il tipo di file è BINARY,
; questo parametro indica il numero di long
; che verranno scritte/lette.
DEV:record = -1 ; indica al device di eseguire loperazione a
; partire dalla fine del file (accodamento).
DEV:olong01 = 123456 ; imposta il dato da scrivere
DEV:olong02 = 654321
WAIT NOT DEV:st_busy
WRITE DEV ; esegui il comando di scrittura
WAIT NOT DEV:st_busy ; attende il termine delloperazione
IF DEV:st_error ; verifica se ci sono stati errori in scrittura
<errore>
ENDIF